package com.isoft.demo.service.impl;/*
 *@ClassName: CompensationServiceImpl
 *@Date: 2021/7/7
 *@Author:刘逸飞
 */

import com.isoft.demo.common.ResponseData;
import com.isoft.demo.dao.CompensationDao;
import com.isoft.demo.entity.Compensation;
import com.isoft.demo.entity.Orders;
import com.isoft.demo.service.CompensationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class CompensationServiceImpl implements CompensationService {
    @Resource
    private CompensationDao dao;
    @Override
    public ResponseData addCom(Compensation com) {
        int n = dao.addCom(com);
        ResponseData rs = new ResponseData();
        List list = new ArrayList();
        if(n > 0){
            rs.setCode(0);
            rs.setMsg("提交成功！");
            list.add(com);
            rs.setData(list);
        } else{
            rs.setCode(1);
            rs.setMsg("提交失败!");
        }
        return rs;
    }

    @Override
    public ResponseData searchComOid() {
        List<Orders> list = dao.searchComOid();
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }

    @Override
    public ResponseData searchAllCom() {
        List<Compensation> list = dao.searchAllCom();
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }

    @Override
    public ResponseData searchComById(int oid) {
        List<Compensation> list = dao.searchComById(oid);
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }

    @Override
    public ResponseData confirmCom(String date,String eid, int comid) {
        int m = dao.confirmCom(date,eid,comid);
        ResponseData rs = new ResponseData();
        if(m != 0){
            rs.setCode(0);
            rs.setMsg("确认成功！");
        } else{
            rs.setCode(1);
            rs.setMsg("确认失败!");
        }
        return rs;
    }

    @Override
    public ResponseData findComeid() {
        List<Orders> list = dao.searchComOid();
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }


}
